package com.jic.market.controller.manage;


import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.market.api.manage.ActivityPriorityApi;
import com.jic.market.common.util.BeanUtil;
import com.jic.market.entity.activity.ActivityPriority;
import com.jic.market.request.ActivityPriorityRequest;
import com.jic.market.response.ActivityPriorityResponse;
import com.jic.market.service.activity.ActivityPriorityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;



/**
 * description: 结算优先级Controller
 * date: 2020/3/15 14:33
 * author: zxl
 * version: 1.0
 */
@Api(tags = {"结算优先级Controller"})
@Slf4j
@RestController
@RequestMapping("/activityPriority")
public class ActivityPriorityController implements ActivityPriorityApi {


    @Autowired
    ActivityPriorityService activityPriorityService;

    /**
     * 分页查询
     * @param form
     * @param form
     * @return
     */
    @PostMapping("/queryPage")
    @ResponseBody
    @Override
    @ApiOperation(value = "分页查询")
    public RestResult<PageResult<ActivityPriorityResponse>> list(@RequestBody ActivityPriorityRequest form) {
        log.info("开始获取所有列表=========》,{}", form.toString());
        Page page = new Page();
        page.setLimit(form.getLimit());
        page.setStart(form.getStart());
        ActivityPriority activityPriority = BeanUtil.copy(form, ActivityPriority.class);
        activityPriority.setDeleteFlag(0L);
        PageResult<ActivityPriority> result = activityPriorityService.queryPage(activityPriority, page);
        List<ActivityPriorityResponse> activityPriorityResponseList = result.getRows().stream().map(temp -> {
            ActivityPriorityResponse activityPriorityResponse = BeanUtil.copy(temp, ActivityPriorityResponse.class);
            return activityPriorityResponse;
        }).filter(item -> item != null).collect(Collectors.toList());
        PageResult<ActivityPriorityResponse> pageResult = new PageResult<>();
        pageResult.setRows(activityPriorityResponseList);
        pageResult.setTotal(result.getTotal());
        return RestResult.success(pageResult);
    }

    /**
     * 结算优先级排序修改
     * @param form
     * @param form
     * @return
     */
    @PostMapping("/updateActivityPrioritySort")
    @ResponseBody
    @ApiOperation(value = "结算优先级排序修改")
    public RestResult updateActivityPrioritySort(@RequestBody ActivityPriorityRequest form){

        Boolean flag = activityPriorityService.updateActivityPrioritySort(form);
        return RestResult.success(flag);
    }

}
